// riderDistribution/pages/order_statistics/order_statistics.js
var common = require("../../../common/common.js").common;

Page({
    /**
   * 页面的初始数据
   */
    data: {
        page: 1,
        pageSize: 10,
        typeList: [ {
            id: 1,
            value: "今日"
        }, {
            id: 2,
            value: "本周"
        }, {
            id: 3,
            value: "本月"
        }, {
            id: 0,
            value: "所有"
        } ],
        type: 1,
        list: []
    },
    /**
   * 生命周期函数--监听页面加载
   */
    onLoad: function(options) {
        this.getList();
    },
    /**
   * 生命周期函数--监听页面初次渲染完成
   */
    onReady: function() {},
    /**
   * 生命周期函数--监听页面显示
   */
    onShow: function() {},
    /**
   * 生命周期函数--监听页面隐藏
   */
    onHide: function() {},
    /**
   * 生命周期函数--监听页面卸载
   */
    onUnload: function() {},
    /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
    onPullDownRefresh: function() {},
    /**
   * 页面上拉触底事件的处理函数
   */
    onReachBottom: function() {
        if (this.data.total > this.data.page * this.data.pageSize) {
            this.setData({
                page: this.data.page + 1
            });
            this.getList(true);
        }
    },
    /**
   * 用户点击右上角分享
   */
    onShareAppMessage: function() {},
    chooseType: function(e) {
        this.setData({
            page: 1,
            type: e.currentTarget.dataset.id
        });
        this.getList();
    },
    getList: function(status) {
        let _this = this;
        common.request({
            endpoint: "Rider/rider/rider-order-statis",
            method: "post",
            data: {
                page: _this.data.page,
                type: _this.data.type
            },
            success: res => {
                var list = res.extra.rows;
                _this.setData({
                    list: status ? _this.data.list.concat(list) : list,
                    total: res.extra.total
                });
            }
        });
    }
});